<?php

namespace App\Http\Controllers\Api;

use App\AdPosition;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class AdPositionController extends BaseController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $pageSize = $request->page_size ? $request->page_size : $this->pageSize;
        return AdPosition::paginate($pageSize);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        AdPosition::create($request->all());
        return response(['message' => '创建成功']);
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\AdPosition  $position
     * @return \Illuminate\Http\Response
     */
    public function show(AdPosition $position)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\AdPosition  $adPosition
     * @return \Illuminate\Http\Response
     */
    public function edit(AdPosition $adPosition)
    {
        //
    }

    /**
     * @param Request $request
     * @param AdPosition $position
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    public function update(Request $request, AdPosition $position)
    {
        $position->update($request->only(['name', 'width', 'height']));
        return response(['message' => '修改成功']);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\AdPosition  $position
     * @return \Illuminate\Http\Response
     */
    public function destroy(AdPosition $position)
    {
        $position->delete();
        return response(['message' => '删除成功']);
    }
}
